package club.tclyq.good_time.common.utils.base64util;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;

/**
 * @author tanchong
 * Create Date: 2019/2/21
 */
public class ImgToBase64 {
    public static String getImageStr(MultipartFile file) throws IOException {
        byte[] data;
        try {
            data = file.getBytes();
        } catch (IOException e) {
            throw new IOException("文件读取异常");
        }
        return "data:image/png;base64," + Base64.getEncoder().encodeToString(data);
    }
}
